package controller

import (
	"fmt"
	"html/template"
	"io"
	"net/http"
	"os"
)

func UpdateOne(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		r.ParseMultipartForm(32 << 20)
		file,header,err := r.FormFile("file")
		if err != nil{
			fmt.Printf("file err:%v\n",err)
			return
		}
		defer file.Close()
		cur,err := os.Create("src/test/http/frame/upload/" + header.Filename)
		if err != nil {
			fmt.Printf("os.create err:%s\v",err)
		}
		defer cur.Close()
		io.Copy(cur,file)
		w.Write([]byte("上传成功"))
	} else {
		t, err := template.ParseFiles("src/test/http/frame/views/index/update_one.html")
		if err != nil{
			fmt.Printf("err:%vn",err)
			return
		}
		t.Execute(w, nil)
	}

}

func Update(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("hello2"))
}
